# import os
# import torch
# import torchvision
# from torch import nn
# from d2l import torch as d2l

# 微调
# def load_cifar10(is_train,augs,batch_size):
#     dataset = torchvision.datasets.CIFAR10(root='./dataset', train=is_train,transform=augs, download=True)
#     dataloader = torch.utils.data.DataLoader(dataset, batch_size=batch_size,shuffle = is_train,
#                         num_workers=d2l.get_dataloader_workers())
#     return dataloader
#
# normalize = torchvision.transforms.Normalize(
#     [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
#
# train_aug = torchvision.transforms.Compose([
#     torchvision.transforms.RandomResizedCrop(224),
#     torchvision.transforms.RandomHorizontalFlip(),
#     torchvision.transforms.ToTensor(),normalize])
#
# test_augs = torchvision.transforms.Compose([
#     torchvision.transforms.Resize(256),
#     torchvision.transforms.CenterCrop(224),
#     torchvision.transforms.ToTensor(),normalize])
#
# finetune_net = torchvision.models.resnet18()
# finetune_net.fc = nn.Linear(finetune_net.fc.in_features,10)
# nn.init.xavier_uniform_(finetune_net.fc.weight)
#
# def train_fine_tuning(net,learing_rate,batch_size=128,num_epochs=5,param_group=True):
#     train_iter = load_cifar10(is_train=True,augs=train_aug,batch_size=batch_size)
#     test_iter = load_cifar10(is_train=False,augs=test_augs,batch_size=batch_size)
#     devices = d2l.try_all_gpus()
#     loss = nn.CrossEntropyLoss(reduction='none')
#     if param_group:
#         params_1x = [
#             param for name,param in net.named_parameters()
#             if name not in["fc.weight","fc.bias"]]
#         trainer = torch.optim.SGD([{
#             'params': params_1x},{'params':net.fc.parameters(),'lr':learing_rate*10}],lr=learing_rate
#         ,weight_decay=0.001)
#     else:
#         trainer = torch.optim.SGD(net.parameters(),lr=learing_rate,weight_decay=0.001)
#     d2l.train_ch13(net,train_iter, test_iter, loss, trainer, num_epochs, devices)
#     d2l.plt.show()
#
# train_fine_tuning(net=finetune_net,learing_rate=5e-5,param_group=False)

# 实战项目
import collections
import math
import os
import shutil
import pandas as pd
import torch
import torchvision
from torch import nn
from d2l import torch as d2l

data_dir = "D:/PytorchLearn/Ci-far10"

# def read_csv_labels(fname):
#     with open(fname,'r') as f:
#         lines = f.readlines()[1:]
#     tokens = [l.rstrip().split(',') for l in lines]
#     return dict(((name,label) for name , label in tokens))
#
# labels = read_csv_labels(os.path.join(data_dir,'trainLabels.csv'))
# print(labels)
# print(len(set(labels.values())))

a_s = ("Sada ads  s   ")
tokens = a_s.rstrip().split(',')
print(tokens)